package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.ysd.entity.Admin;
import com.ysd.util.DBManger;
import com.ysd.util.Result;

public class AdminDaoImpl {
	/**
	 * 根据账号查询信息
	 * @param username
	 * @return
	 */
	public Admin getAdminByUsername(String username) {
		Connection conn = DBManger.getConnection();
		Statement st = null;
		ResultSet rs = null;
		Admin admin = null;
		
		try {
			st=conn.createStatement();
			rs = st.executeQuery("SELECT * from admin where username='"+username+"'");
			while(rs.next()) {
				int id = rs.getInt(1);
				String uname = rs.getString(2);
				String password=rs.getString(3);
				 admin = new Admin(id, uname, password);//构造方法用来创建对象 当new的时候调用
				
			}
			return admin;
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
}
